﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace _006_冒泡排序扩展
{
    class Program
    {
        static int[] Bubble(int[] arr)
        {
            bool swapped = true;
            do
            {
                swapped = false;
                for (int i = 0; i < arr.Length - 1; i++)
                {
                    if (arr[i] > arr[i + 1])
                    {
                        int temp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = temp;
                        swapped = true;
                    }
                }
            } while (swapped);

            return arr;
        }

        public static void Srot<T>(List<T> sortArr, Func<T, T, bool> comparision)
        {
            bool swapped = true;
            do
            {
                swapped = false;
                for (int i = 0; i < sortArr.Count - 1; i++)
                {
                    if (comparision(sortArr[i], sortArr[i + 1]))
                    {
                        T temp = sortArr[i];
                        sortArr[i] = sortArr[i + 1];
                        sortArr[i + 1] = temp;
                        swapped = true;
                    }
                }
            } while (swapped);
        }


        static void Main(string[] args)
        {
            Employee e1 = new Employee("111", 152);
            Employee e2 = new Employee("111", 358);
            Employee e3 = new Employee("111", 12);
            List<Employee> list = new List<Employee> {e1, e2, e3};
            Srot(list, Employee.CompareSalary);
            list.ForEach(r => { Console.WriteLine(r.Salary); });
            Console.ReadKey();
        }
    }

    class Employee
    {
        public Employee(string name, decimal salary)
        {
            this.Name = name;
            this.Salary = salary;
        }
        public string Name { get; private set; }
        public decimal Salary { get; private set; }

        public static bool CompareSalary(Employee e1, Employee e2)
        {
            return e1.Salary > e2.Salary;
        }
    }
}
